import { MetaMaskProvider } from 'web3-types/lib/types/web3_base_provider';

interface EIP6963ProviderInfo {
    rdns: string
    uuid: string
    name: string
    icon: string
}

interface EIP6963ProviderDetail {
    info: EIP6963ProviderInfo
    provider: EIP1193Provider
}

type EIP6963AnnounceProviderEvent = {
    detail: {
        info: EIP6963ProviderInfo,
        provider: Readonly<EIP1193Provider>,
    }
}

interface EIP1193Provider {
    isStatus?: boolean
    host?: string
    path?: string
    sendAsync?: (request: { method: string, params?: Array<unknown> }, callback: (error: Error | null, response: unknown) => void) => void
    send?: (request: { method: string, params?: Array<unknown> }, callback: (error: Error | null, response: unknown) => void) => void
    request: (request: { method: string, params?: Array<unknown> }) => Promise<unknown>
}

declare global {
    interface Window {
        ethereum: MetaMaskProvider
    }
}
interface EIP6963ProviderInfo {
    walletId: string
    uuid: string
    name: string
    icon: string
}

// Represents the structure of an Ethereum provider based on the EIP-1193 standard
interface EIP1193Provider {
    isStatus?: boolean
    host?: string
    path?: string
    sendAsync?: (request: { method: string, params?: Array<unknown> }, callback: (error: Error | null, response: unknown) => void) => void
    send?: (request: { method: string, params?: Array<unknown> }, callback: (error: Error | null, response: unknown) => void) => void
    request: (request: { method: string, params?: Array<unknown> }) => Promise<unknown>
}

// Combines the provider's metadata with an actual provider object
// Creating a complete picture of a wallet provider at a glance and for purposes of working with them
interface EIP6963ProviderDetail {
    info: EIP6963ProviderInfo
    provider: EIP1193Provider
}

// An error object with optional properties, commonly encountered when handling MetaMask `eth_requestAccounts` errors
interface MMError {
    code?: string
    message?: string
}

declare global{
    interface WindowEventMap {
        'eip6963:announceProvider': CustomEvent
    }
}

